package com.weiyi.mashangzhu.Roomer.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Bean.CouponBean;
import com.weiyi.mashangzhu.Roomer.Bean.OrderDetailsBean;

import java.util.List;

/**
 * Created by win7 on 2017/5/12.
 */

public class Coupon_OrderAdapter extends BaseAdapter {
    List<OrderDetailsBean.DataBean.CouponlistBean> list_o;
    Context context;
    String info;

    public Coupon_OrderAdapter(List<OrderDetailsBean.DataBean.CouponlistBean> list_o, Context context,String info) {
        this.list_o = list_o;
        this.context = context;
        this.info=info;
    }

    @Override
    public int getCount() {
            return list_o.size();
    }

    @Override
    public Object getItem(int position)
    {
            return list_o.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_coupon, null);
            viewHolder.layout= (LinearLayout) convertView.findViewById(R.id.layout);
            viewHolder.count = (TextView) convertView.findViewById(R.id.count);
            viewHolder.count_man = (TextView) convertView.findViewById(R.id.cout_man);
            viewHolder.time = (TextView) convertView.findViewById(R.id.time);
            convertView.setTag(viewHolder);

        }
        viewHolder = (ViewHolder) convertView.getTag();
            viewHolder.count.setText(list_o.get(position).getCPrice() + "");
            viewHolder.count_man.setText(list_o.get(position).getCQuota() + "");
            viewHolder.time.setText("使用时间："+list_o.get(position).getCSdate() + "-" + list_o.get(position).getCEdate());
        if (info.equals("yes")){
            viewHolder.layout.setBackgroundResource(R.mipmap.coupon_on);
        }else {
            viewHolder.layout.setBackgroundResource(R.mipmap.coupon_out);
        }

        return convertView;
    }

    class ViewHolder {
        LinearLayout layout;
        TextView count,count_man,time;
    }
}
